<?php
/**
 * 策略模式
 * This file is part of pattern.
 * Author: tangzhou
 * Date: 2016/9/2
 * Time: 15:51
 * File: Strategy.php
 */

interface test
{
    function test1();
    function test2();
}

class Demo1 implements test
{
    function test1()
    {
        // TODO: Implement test1() method.
    }

    function test2()
    {
        // TODO: Implement test2() method.
    }

}

class Demo2 implements test
{
    function test1()
    {
        // TODO: Implement test1() method.
    }

    function test2()
    {
        // TODO: Implement test2() method.
    }
}


class Strategy
{
    private $item;

    public function getItem($item)
    {
        try{
            $class = new ReflectionClass($item);
            $this->item = $class->newInstance();
        }catch (RedisException $e){
            $this->item = null;
        }
    }

    function test1()
    {
        $this->item->test1();
    }

    function test2()
    {
        $this->item->test2();
    }
}

